|
|
|
|
|
|
|
Figure 4.3
These four labels have the same long caption; their AutoSize and WordWrap properties determine whether and how they resize to fit the caption. |
|
|
|
|
CAUTION
|
|
|
|
|
To preserve the original width of your label control, you must set the WordWrap property to True before setting the AutoSize property. Otherwise, when you set the AutoSize property to True, the label control adjusts horizontally to fit the current contents of the Caption property. |
|
|
|
|
|
|
| |
|
|
|
|
When assigning a label's Caption property, you can force a new line by including a carriage return and line feed combination. This technique, as well as its nomenclature, is a throwback to the ancient days of manual typewriters. When a manual typewriter user reached the end of a line, he or she had to move the paper up manually to the next line (a line feed) and return the carriage to the beginning of that line (a carriage return). In Visual Basic, you can insert a carriage return/line feed combination by inserting ASCII characters 13 and 10 into the caption at the point where the line should break. Visual Basic supplies a predefined constant, vbCrLf, to help you accomplish this task: |
|
|
|
|
|
|
|
|
Label1.caption = "First Line" & vbCrLf & "Second Line" |
|
|
|
|
|
|
|
|
|
|
Controlling the Appearance of Text |
|
|
|
|
|
|
|
|
The Caption property contains the text to be displayed, but other properties control the appearance of the text. You have already looked at AutoSize and WordWrap; other properties are listed here: |
|
|
|
|
|
|
|
|
AlignmentControls text justification (left, right, or centered) |
|
|
|
|
|
|
|
|
AppearanceCauses the label to look flat or three-dimensional |
|
|
|
|
|
|
|
|
BorderStyleDetermines whether the label control has a border |
|
|
|
|
|
|
|
|
FontMakes the text boldface, underlined, italic, or changes the typeface |
|
|
|
|
|
|
|
|
ForeColor and BackColorControl the color of the text and the label background |
|
|
|
|
|
|
|
|
UseMnemonicControls whether an ampersand (&) in the Caption property is treated like an access key indicator |
|
|
|
|
|
|
|
|
|
With BorderStyle set to Fixed Single, the label control takes on the appearance of a noneditable text box.  |
|
|
|
|
|
|
|
|
|
|
You can set these properties to provide any different number of visual effects to emphasize text in the label and other controls. The effects of setting some of these properties are shown in Figure 4.4. |
|
|
|
|
|